package com.atguigu.tingshu.user.api;

import com.atguigu.tingshu.common.login.TsLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.util.AuthContextHolder;
import com.atguigu.tingshu.user.service.UserInfoService;
import com.atguigu.tingshu.vo.user.UserInfoVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Tag(name = "用户管理接口")
@RestController
@RequestMapping("api/user/userInfo")
@SuppressWarnings({"all"})
public class UserInfoApiController {

	@Autowired
	private UserInfoService userInfoService;

	/**
	 * @author gengjian
	 * @date 2025/02/26 17:03:46
	 * 根据用户id查询用户信息
	 */
	@GetMapping("getUserInfo/{userId}")
	Result<UserInfoVo> getUserInfo(@PathVariable("userId") Long userId){
		//调用服务层方法
		UserInfoVo userInfoVo = userInfoService.getUserInfo(userId);
		return Result.ok(userInfoVo);
	}

	/**
	 * 判断用户是否购买声音列表
	 * @param albumId
	 * @param trackIdList
	 * @return
	 */
	@TsLogin(requiredLogin = true)
	@Operation(summary = "判断用户是否购买声音列表")
	@PostMapping("/userIsPaidTrack/{albumId}")
	Result<Map<Long, Integer>> userIsPaidTrack(@RequestBody List<Long> trackIdList, @PathVariable Long albumId){
		//获取用户id
		Long userId = AuthContextHolder.getUserId();
		//调用服务层方法
		Map<Long,Integer> map = userInfoService.userIsPaidTrack(trackIdList,albumId,userId);
		return Result.ok(map);
	}
}

